namespace PMS.BLL
{
    using PMS.Common;
    using PMS.DBUtility;
    using PMS.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;
    using System.Text;

    public class UserChangeLogBLL
    {
        public int Add(UserChangeLog model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into UserChangeLog(");
            builder.Append("Birthday,ID,Birthplace,Nation,Politics,JoinPartDate,GraduationDate,GraduationSchoole,HighestEducation,Degree,LogType,Major,JoinWorkDate,Photo,IsOfficer,Remark,RegistDay,RegistWay,RegistFrom,RegistTo,OrganID,RegistNo,CheckState,RegistDate,RegistSummary,RegistRemark,RegistState,RegistType,UserType,IsHeighWith,JobPositionType,JobPositionName1,JobPositionDate1,CheckAdminID,JobPositionName2,JobPositionDate2,JobPositionNo,JobPositionDate,JobPositionSummary,JobPositionRemark,AdminPosition,EvaluationDate,Position1,PositionLevel1,CheckDate,JobTitle1,PositionStartDate1,PositionEndDate1,PositionNo1,PositionDate1,PositionRemark1,IsDoublePosition,Position2,PositionLevel2,JobTitle2,CheckRemark,PositionStartDate2,PositionEndDate2,PositionNo2,PositionDate2,PositionRemark2,Class,ClassDate,IsLeave,LeaveReasion,LeaveDay,UserID,LeaveTo,LeaveNo,LeaveDate,LeaveSummary,LeaveRemark,AddUser,AddDate,UpdateUser,UpdateDate,Backup1,UserName,Backup2,Backup3,Backup4,Backup5,Backup6,Backup7,Sex");
            builder.Append(") values (");
            builder.Append("@Birthday,@ID,@Birthplace,@Nation,@Politics,@JoinPartDate,@GraduationDate,@GraduationSchoole,@HighestEducation,@Degree,@LogType,@Major,@JoinWorkDate,@Photo,@IsOfficer,@Remark,@RegistDay,@RegistWay,@RegistFrom,@RegistTo,@OrganID,@RegistNo,@CheckState,@RegistDate,@RegistSummary,@RegistRemark,@RegistState,@RegistType,@UserType,@IsHeighWith,@JobPositionType,@JobPositionName1,@JobPositionDate1,@CheckAdminID,@JobPositionName2,@JobPositionDate2,@JobPositionNo,@JobPositionDate,@JobPositionSummary,@JobPositionRemark,@AdminPosition,@EvaluationDate,@Position1,@PositionLevel1,@CheckDate,@JobTitle1,@PositionStartDate1,@PositionEndDate1,@PositionNo1,@PositionDate1,@PositionRemark1,@IsDoublePosition,@Position2,@PositionLevel2,@JobTitle2,@CheckRemark,@PositionStartDate2,@PositionEndDate2,@PositionNo2,@PositionDate2,@PositionRemark2,@Class,@ClassDate,@IsLeave,@LeaveReasion,@LeaveDay,@UserID,@LeaveTo,@LeaveNo,@LeaveDate,@LeaveSummary,@LeaveRemark,@AddUser,@AddDate,@UpdateUser,@UpdateDate,@Backup1,@UserName,@Backup2,@Backup3,@Backup4,@Backup5,@Backup6,@Backup7,@Sex");
            builder.Append(") ");
            builder.Append(";select @@IDENTITY");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@Birthday", model.Birthday), new SqlParameter("@ID", model.ID), new SqlParameter("@Birthplace", model.Birthplace), new SqlParameter("@Nation", model.Nation), new SqlParameter("@Politics", model.Politics), new SqlParameter("@JoinPartDate", model.JoinPartDate), new SqlParameter("@GraduationDate", model.GraduationDate), new SqlParameter("@GraduationSchoole", model.GraduationSchoole), new SqlParameter("@HighestEducation", model.HighestEducation), new SqlParameter("@Degree", model.Degree), new SqlParameter("@LogType", model.LogType), new SqlParameter("@Major", model.Major), new SqlParameter("@JoinWorkDate", model.JoinWorkDate), new SqlParameter("@Photo", model.Photo), new SqlParameter("@IsOfficer", model.IsOfficer), new SqlParameter("@Remark", model.Remark), 
                new SqlParameter("@RegistDay", model.RegistDay), new SqlParameter("@RegistWay", model.RegistWay), new SqlParameter("@RegistFrom", model.RegistFrom), new SqlParameter("@RegistTo", model.RegistTo), new SqlParameter("@OrganID", model.OrganID), new SqlParameter("@RegistNo", model.RegistNo), new SqlParameter("@CheckState", model.CheckState), new SqlParameter("@RegistDate", model.RegistDate), new SqlParameter("@RegistSummary", model.RegistSummary), new SqlParameter("@RegistRemark", model.RegistRemark), new SqlParameter("@RegistState", model.RegistState), new SqlParameter("@RegistType", model.RegistType), new SqlParameter("@UserType", model.UserType), new SqlParameter("@IsHeighWith", model.IsHeighWith), new SqlParameter("@JobPositionType", model.JobPositionType), new SqlParameter("@JobPositionName1", model.JobPositionName1), 
                new SqlParameter("@JobPositionDate1", model.JobPositionDate1), new SqlParameter("@CheckAdminID", model.CheckAdminID), new SqlParameter("@JobPositionName2", model.JobPositionName2), new SqlParameter("@JobPositionDate2", model.JobPositionDate2), new SqlParameter("@JobPositionNo", model.JobPositionNo), new SqlParameter("@JobPositionDate", model.JobPositionDate), new SqlParameter("@JobPositionSummary", model.JobPositionSummary), new SqlParameter("@JobPositionRemark", model.JobPositionRemark), new SqlParameter("@AdminPosition", model.AdminPosition), new SqlParameter("@EvaluationDate", model.EvaluationDate), new SqlParameter("@Position1", model.Position1), new SqlParameter("@PositionLevel1", model.PositionLevel1), new SqlParameter("@CheckDate", model.CheckDate), new SqlParameter("@JobTitle1", model.JobTitle1), new SqlParameter("@PositionStartDate1", model.PositionStartDate1), new SqlParameter("@PositionEndDate1", model.PositionEndDate1), 
                new SqlParameter("@PositionNo1", model.PositionNo1), new SqlParameter("@PositionDate1", model.PositionDate1), new SqlParameter("@PositionRemark1", model.PositionRemark1), new SqlParameter("@IsDoublePosition", model.IsDoublePosition), new SqlParameter("@Position2", model.Position2), new SqlParameter("@PositionLevel2", model.PositionLevel2), new SqlParameter("@JobTitle2", model.JobTitle2), new SqlParameter("@CheckRemark", model.CheckRemark), new SqlParameter("@PositionStartDate2", model.PositionStartDate2), new SqlParameter("@PositionEndDate2", model.PositionEndDate2), new SqlParameter("@PositionNo2", model.PositionNo2), new SqlParameter("@PositionDate2", model.PositionDate2), new SqlParameter("@PositionRemark2", model.PositionRemark2), new SqlParameter("@Class", model.Class), new SqlParameter("@ClassDate", model.ClassDate), new SqlParameter("@IsLeave", model.IsLeave), 
                new SqlParameter("@LeaveReasion", model.LeaveReasion), new SqlParameter("@LeaveDay", model.LeaveDay), new SqlParameter("@UserID", model.UserID), new SqlParameter("@LeaveTo", model.LeaveTo), new SqlParameter("@LeaveNo", model.LeaveNo), new SqlParameter("@LeaveDate", model.LeaveDate), new SqlParameter("@LeaveSummary", model.LeaveSummary), new SqlParameter("@LeaveRemark", model.LeaveRemark), new SqlParameter("@AddUser", model.AddUser), new SqlParameter("@AddDate", model.AddDate), new SqlParameter("@UpdateUser", model.UpdateUser), new SqlParameter("@UpdateDate", model.UpdateDate), new SqlParameter("@Backup1", model.Backup1), new SqlParameter("@UserName", model.UserName), new SqlParameter("@Backup2", model.Backup2), new SqlParameter("@Backup3", model.Backup3), 
                new SqlParameter("@Backup4", model.Backup4), new SqlParameter("@Backup5", model.Backup5), new SqlParameter("@Backup6", model.Backup6), new SqlParameter("@Backup7", model.Backup7), new SqlParameter("@Sex", model.Sex)
             };
            object single = DBHelper.GetSingle(builder.ToString(), cmdParms);
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }

        public bool Check(int LogID, string checkState, string CheckRemark)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update UserChangeLog set ");
            builder.Append(" CheckState = @CheckState , ");
            builder.Append(" CheckDate = @CheckDate , ");
            builder.Append(" CheckAdminID = @CheckAdminID , ");
            builder.Append(" CheckRemark = @CheckRemark  ");
            builder.Append(" where LogID=@LogID ");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@LogID", LogID), new SqlParameter("@CheckState", checkState), new SqlParameter("@CheckDate", DateTime.Now), new SqlParameter("@CheckAdminID", Keys.Admin.AdminID), new SqlParameter("@CheckRemark", CheckRemark) };
            return (DBHelper.ExecuteSql(builder.ToString(), cmdParms) > 0);
        }

        public bool Delete(int LogID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from UserChangeLog ");
            builder.Append(" where LogID=@LogID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@LogID", SqlDbType.Int, 4) };
            cmdParms[0].Value = LogID;
            return (DBHelper.ExecuteSql(builder.ToString(), cmdParms) > 0);
        }

        public bool DeleteList(string LogIDlist)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from UserChangeLog ");
            builder.Append(" where ID in (" + LogIDlist + ")  ");
            return (DBHelper.ExecuteSql(builder.ToString()) > 0);
        }

        public List<UserChangeLog> GetList()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select * ");
            builder.Append(" FROM  UserChangeLog ");
            DataTable table = DBHelper.Query(builder.ToString()).Tables[0];
            UserChangeLog item = null;
            List<UserChangeLog> list = null;
            if (table.Rows.Count > 0)
            {
                list = new List<UserChangeLog>();
                foreach (DataRow row in table.Rows)
                {
                    item = new UserChangeLog();
                    if (row["LogID"].ToString() != "")
                    {
                        item.LogID = int.Parse(row["LogID"].ToString());
                    }
                    if (row["Birthday"].ToString() != "")
                    {
                        item.Birthday = new DateTime?(DateTime.Parse(row["Birthday"].ToString()));
                    }
                    item.ID = row["ID"].ToString();
                    item.Birthplace = row["Birthplace"].ToString();
                    item.Nation = row["Nation"].ToString();
                    item.Politics = row["Politics"].ToString();
                    if (row["JoinPartDate"].ToString() != "")
                    {
                        item.JoinPartDate = new DateTime?(DateTime.Parse(row["JoinPartDate"].ToString()));
                    }
                    if (row["GraduationDate"].ToString() != "")
                    {
                        item.GraduationDate = new DateTime?(DateTime.Parse(row["GraduationDate"].ToString()));
                    }
                    item.GraduationSchoole = row["GraduationSchoole"].ToString();
                    item.HighestEducation = row["HighestEducation"].ToString();
                    item.Degree = row["Degree"].ToString();
                    item.LogType = row["LogType"].ToString();
                    item.Major = row["Major"].ToString();
                    if (row["JoinWorkDate"].ToString() != "")
                    {
                        item.JoinWorkDate = new DateTime?(DateTime.Parse(row["JoinWorkDate"].ToString()));
                    }
                    item.Photo = row["Photo"].ToString();
                    if (row["IsOfficer"].ToString() != "")
                    {
                        item.IsOfficer = new int?(int.Parse(row["IsOfficer"].ToString()));
                    }
                    item.Remark = row["Remark"].ToString();
                    if (row["RegistDay"].ToString() != "")
                    {
                        item.RegistDay = new DateTime?(DateTime.Parse(row["RegistDay"].ToString()));
                    }
                    item.RegistWay = row["RegistWay"].ToString();
                    item.RegistFrom = row["RegistFrom"].ToString();
                    item.RegistTo = row["RegistTo"].ToString();
                    if (row["OrganID"].ToString() != "")
                    {
                        item.OrganID = new int?(int.Parse(row["OrganID"].ToString()));
                    }
                    item.RegistNo = row["RegistNo"].ToString();
                    item.CheckState = row["CheckState"].ToString();
                    if (row["RegistDate"].ToString() != "")
                    {
                        item.RegistDate = new DateTime?(DateTime.Parse(row["RegistDate"].ToString()));
                    }
                    item.RegistSummary = row["RegistSummary"].ToString();
                    item.RegistRemark = row["RegistRemark"].ToString();
                    item.RegistState = row["RegistState"].ToString();
                    item.RegistType = row["RegistType"].ToString();
                    item.UserType = row["UserType"].ToString();
                    if (row["IsHeighWith"].ToString() != "")
                    {
                        item.IsHeighWith = new int?(int.Parse(row["IsHeighWith"].ToString()));
                    }
                    item.JobPositionType = row["JobPositionType"].ToString();
                    item.JobPositionName1 = row["JobPositionName1"].ToString();
                    if (row["JobPositionDate1"].ToString() != "")
                    {
                        item.JobPositionDate1 = new DateTime?(DateTime.Parse(row["JobPositionDate1"].ToString()));
                    }
                    if (row["CheckAdminID"].ToString() != "")
                    {
                        item.CheckAdminID = int.Parse(row["CheckAdminID"].ToString());
                    }
                    item.JobPositionName2 = row["JobPositionName2"].ToString();
                    if (row["JobPositionDate2"].ToString() != "")
                    {
                        item.JobPositionDate2 = new DateTime?(DateTime.Parse(row["JobPositionDate2"].ToString()));
                    }
                    item.JobPositionNo = row["JobPositionNo"].ToString();
                    if (row["JobPositionDate"].ToString() != "")
                    {
                        item.JobPositionDate = new DateTime?(DateTime.Parse(row["JobPositionDate"].ToString()));
                    }
                    item.JobPositionSummary = row["JobPositionSummary"].ToString();
                    item.JobPositionRemark = row["JobPositionRemark"].ToString();
                    item.AdminPosition = row["AdminPosition"].ToString();
                    if (row["EvaluationDate"].ToString() != "")
                    {
                        item.EvaluationDate = new DateTime?(DateTime.Parse(row["EvaluationDate"].ToString()));
                    }
                    item.Position1 = row["Position1"].ToString();
                    item.PositionLevel1 = row["PositionLevel1"].ToString();
                    if (row["CheckDate"].ToString() != "")
                    {
                        item.CheckDate = new DateTime?(DateTime.Parse(row["CheckDate"].ToString()));
                    }
                    item.JobTitle1 = row["JobTitle1"].ToString();
                    if (row["PositionStartDate1"].ToString() != "")
                    {
                        item.PositionStartDate1 = new DateTime?(DateTime.Parse(row["PositionStartDate1"].ToString()));
                    }
                    if (row["PositionEndDate1"].ToString() != "")
                    {
                        item.PositionEndDate1 = new DateTime?(DateTime.Parse(row["PositionEndDate1"].ToString()));
                    }
                    item.PositionNo1 = row["PositionNo1"].ToString();
                    if (row["PositionDate1"].ToString() != "")
                    {
                        item.PositionDate1 = new DateTime?(DateTime.Parse(row["PositionDate1"].ToString()));
                    }
                    item.PositionRemark1 = row["PositionRemark1"].ToString();
                    if (row["IsDoublePosition"].ToString() != "")
                    {
                        item.IsDoublePosition = new int?(int.Parse(row["IsDoublePosition"].ToString()));
                    }
                    item.Position2 = row["Position2"].ToString();
                    item.PositionLevel2 = row["PositionLevel2"].ToString();
                    item.JobTitle2 = row["JobTitle2"].ToString();
                    item.CheckRemark = row["CheckRemark"].ToString();
                    if (row["PositionStartDate2"].ToString() != "")
                    {
                        item.PositionStartDate2 = new DateTime?(DateTime.Parse(row["PositionStartDate2"].ToString()));
                    }
                    if (row["PositionEndDate2"].ToString() != "")
                    {
                        item.PositionEndDate2 = new DateTime?(DateTime.Parse(row["PositionEndDate2"].ToString()));
                    }
                    item.PositionNo2 = row["PositionNo2"].ToString();
                    if (row["PositionDate2"].ToString() != "")
                    {
                        item.PositionDate2 = new DateTime?(DateTime.Parse(row["PositionDate2"].ToString()));
                    }
                    item.PositionRemark2 = row["PositionRemark2"].ToString();
                    item.Class = row["Class"].ToString();
                    if (row["ClassDate"].ToString() != "")
                    {
                        item.ClassDate = new DateTime?(DateTime.Parse(row["ClassDate"].ToString()));
                    }
                    if (row["IsLeave"].ToString() != "")
                    {
                        item.IsLeave = new int?(int.Parse(row["IsLeave"].ToString()));
                    }
                    item.LeaveReasion = row["LeaveReasion"].ToString();
                    if (row["LeaveDay"].ToString() != "")
                    {
                        item.LeaveDay = new DateTime?(DateTime.Parse(row["LeaveDay"].ToString()));
                    }
                    if (row["UserID"].ToString() != "")
                    {
                        item.UserID = int.Parse(row["UserID"].ToString());
                    }
                    item.LeaveTo = row["LeaveTo"].ToString();
                    item.LeaveNo = row["LeaveNo"].ToString();
                    if (row["LeaveDate"].ToString() != "")
                    {
                        item.LeaveDate = new DateTime?(DateTime.Parse(row["LeaveDate"].ToString()));
                    }
                    item.LeaveSummary = row["LeaveSummary"].ToString();
                    item.LeaveRemark = row["LeaveRemark"].ToString();
                    item.AddUser = row["AddUser"].ToString();
                    if (row["AddDate"].ToString() != "")
                    {
                        item.AddDate = new DateTime?(DateTime.Parse(row["AddDate"].ToString()));
                    }
                    item.UpdateUser = row["UpdateUser"].ToString();
                    if (row["UpdateDate"].ToString() != "")
                    {
                        item.UpdateDate = new DateTime?(DateTime.Parse(row["UpdateDate"].ToString()));
                    }
                    item.Backup1 = row["Backup1"].ToString();
                    item.UserName = row["UserName"].ToString();
                    item.Backup2 = row["Backup2"].ToString();
                    item.Backup3 = row["Backup3"].ToString();
                    item.Backup4 = row["Backup4"].ToString();
                    item.Backup5 = row["Backup5"].ToString();
                    item.Backup6 = row["Backup6"].ToString();
                    item.Backup7 = row["Backup7"].ToString();
                    item.Sex = row["Sex"].ToString();
                    list.Add(item);
                }
            }
            return list;
        }

        public List<UserChangeLog> GetList(string whereStr)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select * ");
            builder.Append(" FROM view_UserChangeLog ");
            builder.Append(" WHERE  CheckState= '").Append("未审核").Append("' ");
            builder.Append(whereStr);
            DataTable table = DBHelper.Query(builder.ToString()).Tables[0];
            UserChangeLog item = null;
            List<UserChangeLog> list = null;
            if (table.Rows.Count > 0)
            {
                list = new List<UserChangeLog>();
                foreach (DataRow row in table.Rows)
                {
                    item = new UserChangeLog();
                    if (row["LogID"].ToString() != "")
                    {
                        item.LogID = int.Parse(row["LogID"].ToString());
                    }
                    item.IUserName = row["IUserName"].ToString();
                    if (row["Birthday"].ToString() != "")
                    {
                        item.Birthday = new DateTime?(DateTime.Parse(row["Birthday"].ToString()));
                    }
                    item.ID = row["ID"].ToString();
                    item.Birthplace = row["Birthplace"].ToString();
                    item.Nation = row["Nation"].ToString();
                    item.Politics = row["Politics"].ToString();
                    if (row["JoinPartDate"].ToString() != "")
                    {
                        item.JoinPartDate = new DateTime?(DateTime.Parse(row["JoinPartDate"].ToString()));
                    }
                    if (row["GraduationDate"].ToString() != "")
                    {
                        item.GraduationDate = new DateTime?(DateTime.Parse(row["GraduationDate"].ToString()));
                    }
                    item.GraduationSchoole = row["GraduationSchoole"].ToString();
                    item.HighestEducation = row["HighestEducation"].ToString();
                    item.Degree = row["Degree"].ToString();
                    item.LogType = row["LogType"].ToString();
                    item.Major = row["Major"].ToString();
                    if (row["JoinWorkDate"].ToString() != "")
                    {
                        item.JoinWorkDate = new DateTime?(DateTime.Parse(row["JoinWorkDate"].ToString()));
                    }
                    item.Photo = row["Photo"].ToString();
                    if (row["IsOfficer"].ToString() != "")
                    {
                        item.IsOfficer = new int?(int.Parse(row["IsOfficer"].ToString()));
                    }
                    item.Remark = row["Remark"].ToString();
                    if (row["RegistDay"].ToString() != "")
                    {
                        item.RegistDay = new DateTime?(DateTime.Parse(row["RegistDay"].ToString()));
                    }
                    item.RegistWay = row["RegistWay"].ToString();
                    item.RegistFrom = row["RegistFrom"].ToString();
                    item.RegistTo = row["RegistTo"].ToString();
                    if (row["OrganID"].ToString() != "")
                    {
                        item.OrganID = new int?(int.Parse(row["OrganID"].ToString()));
                    }
                    item.RegistNo = row["RegistNo"].ToString();
                    item.CheckState = row["CheckState"].ToString();
                    if (row["RegistDate"].ToString() != "")
                    {
                        item.RegistDate = new DateTime?(DateTime.Parse(row["RegistDate"].ToString()));
                    }
                    item.RegistSummary = row["RegistSummary"].ToString();
                    item.RegistRemark = row["RegistRemark"].ToString();
                    item.RegistState = row["RegistState"].ToString();
                    item.RegistType = row["RegistType"].ToString();
                    item.UserType = row["UserType"].ToString();
                    if (row["IsHeighWith"].ToString() != "")
                    {
                        item.IsHeighWith = new int?(int.Parse(row["IsHeighWith"].ToString()));
                    }
                    item.JobPositionType = row["JobPositionType"].ToString();
                    item.JobPositionName1 = row["JobPositionName1"].ToString();
                    if (row["JobPositionDate1"].ToString() != "")
                    {
                        item.JobPositionDate1 = new DateTime?(DateTime.Parse(row["JobPositionDate1"].ToString()));
                    }
                    if (row["CheckAdminID"].ToString() != "")
                    {
                        item.CheckAdminID = int.Parse(row["CheckAdminID"].ToString());
                    }
                    item.JobPositionName2 = row["JobPositionName2"].ToString();
                    if (row["JobPositionDate2"].ToString() != "")
                    {
                        item.JobPositionDate2 = new DateTime?(DateTime.Parse(row["JobPositionDate2"].ToString()));
                    }
                    item.JobPositionNo = row["JobPositionNo"].ToString();
                    if (row["JobPositionDate"].ToString() != "")
                    {
                        item.JobPositionDate = new DateTime?(DateTime.Parse(row["JobPositionDate"].ToString()));
                    }
                    item.JobPositionSummary = row["JobPositionSummary"].ToString();
                    item.JobPositionRemark = row["JobPositionRemark"].ToString();
                    item.AdminPosition = row["AdminPosition"].ToString();
                    if (row["EvaluationDate"].ToString() != "")
                    {
                        item.EvaluationDate = new DateTime?(DateTime.Parse(row["EvaluationDate"].ToString()));
                    }
                    item.Position1 = row["Position1"].ToString();
                    item.PositionLevel1 = row["PositionLevel1"].ToString();
                    if (row["CheckDate"].ToString() != "")
                    {
                        item.CheckDate = new DateTime?(DateTime.Parse(row["CheckDate"].ToString()));
                    }
                    item.JobTitle1 = row["JobTitle1"].ToString();
                    if (row["PositionStartDate1"].ToString() != "")
                    {
                        item.PositionStartDate1 = new DateTime?(DateTime.Parse(row["PositionStartDate1"].ToString()));
                    }
                    if (row["PositionEndDate1"].ToString() != "")
                    {
                        item.PositionEndDate1 = new DateTime?(DateTime.Parse(row["PositionEndDate1"].ToString()));
                    }
                    item.PositionNo1 = row["PositionNo1"].ToString();
                    if (row["PositionDate1"].ToString() != "")
                    {
                        item.PositionDate1 = new DateTime?(DateTime.Parse(row["PositionDate1"].ToString()));
                    }
                    item.PositionRemark1 = row["PositionRemark1"].ToString();
                    if (row["IsDoublePosition"].ToString() != "")
                    {
                        item.IsDoublePosition = new int?(int.Parse(row["IsDoublePosition"].ToString()));
                    }
                    item.Position2 = row["Position2"].ToString();
                    item.PositionLevel2 = row["PositionLevel2"].ToString();
                    item.JobTitle2 = row["JobTitle2"].ToString();
                    item.CheckRemark = row["CheckRemark"].ToString();
                    if (row["PositionStartDate2"].ToString() != "")
                    {
                        item.PositionStartDate2 = new DateTime?(DateTime.Parse(row["PositionStartDate2"].ToString()));
                    }
                    if (row["PositionEndDate2"].ToString() != "")
                    {
                        item.PositionEndDate2 = new DateTime?(DateTime.Parse(row["PositionEndDate2"].ToString()));
                    }
                    item.PositionNo2 = row["PositionNo2"].ToString();
                    if (row["PositionDate2"].ToString() != "")
                    {
                        item.PositionDate2 = new DateTime?(DateTime.Parse(row["PositionDate2"].ToString()));
                    }
                    item.PositionRemark2 = row["PositionRemark2"].ToString();
                    item.Class = row["Class"].ToString();
                    if (row["ClassDate"].ToString() != "")
                    {
                        item.ClassDate = new DateTime?(DateTime.Parse(row["ClassDate"].ToString()));
                    }
                    if (row["IsLeave"].ToString() != "")
                    {
                        item.IsLeave = new int?(int.Parse(row["IsLeave"].ToString()));
                    }
                    item.LeaveReasion = row["LeaveReasion"].ToString();
                    if (row["LeaveDay"].ToString() != "")
                    {
                        item.LeaveDay = new DateTime?(DateTime.Parse(row["LeaveDay"].ToString()));
                    }
                    if (row["UserID"].ToString() != "")
                    {
                        item.UserID = int.Parse(row["UserID"].ToString());
                    }
                    item.LeaveTo = row["LeaveTo"].ToString();
                    item.LeaveNo = row["LeaveNo"].ToString();
                    if (row["LeaveDate"].ToString() != "")
                    {
                        item.LeaveDate = new DateTime?(DateTime.Parse(row["LeaveDate"].ToString()));
                    }
                    item.LeaveSummary = row["LeaveSummary"].ToString();
                    item.LeaveRemark = row["LeaveRemark"].ToString();
                    item.AddUser = row["AddUser"].ToString();
                    if (row["AddDate"].ToString() != "")
                    {
                        item.AddDate = new DateTime?(DateTime.Parse(row["AddDate"].ToString()));
                    }
                    item.UpdateUser = row["UpdateUser"].ToString();
                    if (row["UpdateDate"].ToString() != "")
                    {
                        item.UpdateDate = new DateTime?(DateTime.Parse(row["UpdateDate"].ToString()));
                    }
                    item.Backup1 = row["Backup1"].ToString();
                    item.UserName = row["UserName"].ToString();
                    item.Backup2 = row["Backup2"].ToString();
                    item.Backup3 = row["Backup3"].ToString();
                    item.Backup4 = row["Backup4"].ToString();
                    item.Backup5 = row["Backup5"].ToString();
                    item.Backup6 = row["Backup6"].ToString();
                    item.Backup7 = row["Backup7"].ToString();
                    item.Sex = row["Sex"].ToString();
                    list.Add(item);
                }
            }
            return list;
        }

        public List<UserChangeLog> GetList(string CheckState, string whereStr = "")
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select * ");
            builder.Append(" FROM view_UserChangeLog ");
            builder.Append(" WHERE  CheckState= '").Append(CheckState).Append("' ");
            builder.Append(whereStr);
            DataTable table = DBHelper.Query(builder.ToString()).Tables[0];
            UserChangeLog item = null;
            List<UserChangeLog> list = null;
            if (table.Rows.Count > 0)
            {
                list = new List<UserChangeLog>();
                foreach (DataRow row in table.Rows)
                {
                    item = new UserChangeLog();
                    if (row["LogID"].ToString() != "")
                    {
                        item.LogID = int.Parse(row["LogID"].ToString());
                    }
                    item.IUserName = row["IUserName"].ToString();
                    if (row["Birthday"].ToString() != "")
                    {
                        item.Birthday = new DateTime?(DateTime.Parse(row["Birthday"].ToString()));
                    }
                    item.ID = row["ID"].ToString();
                    item.Birthplace = row["Birthplace"].ToString();
                    item.Nation = row["Nation"].ToString();
                    item.Politics = row["Politics"].ToString();
                    if (row["JoinPartDate"].ToString() != "")
                    {
                        item.JoinPartDate = new DateTime?(DateTime.Parse(row["JoinPartDate"].ToString()));
                    }
                    if (row["GraduationDate"].ToString() != "")
                    {
                        item.GraduationDate = new DateTime?(DateTime.Parse(row["GraduationDate"].ToString()));
                    }
                    item.GraduationSchoole = row["GraduationSchoole"].ToString();
                    item.HighestEducation = row["HighestEducation"].ToString();
                    item.Degree = row["Degree"].ToString();
                    item.LogType = row["LogType"].ToString();
                    item.Major = row["Major"].ToString();
                    if (row["JoinWorkDate"].ToString() != "")
                    {
                        item.JoinWorkDate = new DateTime?(DateTime.Parse(row["JoinWorkDate"].ToString()));
                    }
                    item.Photo = row["Photo"].ToString();
                    if (row["IsOfficer"].ToString() != "")
                    {
                        item.IsOfficer = new int?(int.Parse(row["IsOfficer"].ToString()));
                    }
                    item.Remark = row["Remark"].ToString();
                    if (row["RegistDay"].ToString() != "")
                    {
                        item.RegistDay = new DateTime?(DateTime.Parse(row["RegistDay"].ToString()));
                    }
                    item.RegistWay = row["RegistWay"].ToString();
                    item.RegistFrom = row["RegistFrom"].ToString();
                    item.RegistTo = row["RegistTo"].ToString();
                    if (row["OrganID"].ToString() != "")
                    {
                        item.OrganID = new int?(int.Parse(row["OrganID"].ToString()));
                    }
                    item.RegistNo = row["RegistNo"].ToString();
                    item.CheckState = row["CheckState"].ToString();
                    if (row["RegistDate"].ToString() != "")
                    {
                        item.RegistDate = new DateTime?(DateTime.Parse(row["RegistDate"].ToString()));
                    }
                    item.RegistSummary = row["RegistSummary"].ToString();
                    item.RegistRemark = row["RegistRemark"].ToString();
                    item.RegistState = row["RegistState"].ToString();
                    item.RegistType = row["RegistType"].ToString();
                    item.UserType = row["UserType"].ToString();
                    if (row["IsHeighWith"].ToString() != "")
                    {
                        item.IsHeighWith = new int?(int.Parse(row["IsHeighWith"].ToString()));
                    }
                    item.JobPositionType = row["JobPositionType"].ToString();
                    item.JobPositionName1 = row["JobPositionName1"].ToString();
                    if (row["JobPositionDate1"].ToString() != "")
                    {
                        item.JobPositionDate1 = new DateTime?(DateTime.Parse(row["JobPositionDate1"].ToString()));
                    }
                    if (row["CheckAdminID"].ToString() != "")
                    {
                        item.CheckAdminID = int.Parse(row["CheckAdminID"].ToString());
                    }
                    item.JobPositionName2 = row["JobPositionName2"].ToString();
                    if (row["JobPositionDate2"].ToString() != "")
                    {
                        item.JobPositionDate2 = new DateTime?(DateTime.Parse(row["JobPositionDate2"].ToString()));
                    }
                    item.JobPositionNo = row["JobPositionNo"].ToString();
                    if (row["JobPositionDate"].ToString() != "")
                    {
                        item.JobPositionDate = new DateTime?(DateTime.Parse(row["JobPositionDate"].ToString()));
                    }
                    item.JobPositionSummary = row["JobPositionSummary"].ToString();
                    item.JobPositionRemark = row["JobPositionRemark"].ToString();
                    item.AdminPosition = row["AdminPosition"].ToString();
                    if (row["EvaluationDate"].ToString() != "")
                    {
                        item.EvaluationDate = new DateTime?(DateTime.Parse(row["EvaluationDate"].ToString()));
                    }
                    item.Position1 = row["Position1"].ToString();
                    item.PositionLevel1 = row["PositionLevel1"].ToString();
                    if (row["CheckDate"].ToString() != "")
                    {
                        item.CheckDate = new DateTime?(DateTime.Parse(row["CheckDate"].ToString()));
                    }
                    item.JobTitle1 = row["JobTitle1"].ToString();
                    if (row["PositionStartDate1"].ToString() != "")
                    {
                        item.PositionStartDate1 = new DateTime?(DateTime.Parse(row["PositionStartDate1"].ToString()));
                    }
                    if (row["PositionEndDate1"].ToString() != "")
                    {
                        item.PositionEndDate1 = new DateTime?(DateTime.Parse(row["PositionEndDate1"].ToString()));
                    }
                    item.PositionNo1 = row["PositionNo1"].ToString();
                    if (row["PositionDate1"].ToString() != "")
                    {
                        item.PositionDate1 = new DateTime?(DateTime.Parse(row["PositionDate1"].ToString()));
                    }
                    item.PositionRemark1 = row["PositionRemark1"].ToString();
                    if (row["IsDoublePosition"].ToString() != "")
                    {
                        item.IsDoublePosition = new int?(int.Parse(row["IsDoublePosition"].ToString()));
                    }
                    item.Position2 = row["Position2"].ToString();
                    item.PositionLevel2 = row["PositionLevel2"].ToString();
                    item.JobTitle2 = row["JobTitle2"].ToString();
                    item.CheckRemark = row["CheckRemark"].ToString();
                    if (row["PositionStartDate2"].ToString() != "")
                    {
                        item.PositionStartDate2 = new DateTime?(DateTime.Parse(row["PositionStartDate2"].ToString()));
                    }
                    if (row["PositionEndDate2"].ToString() != "")
                    {
                        item.PositionEndDate2 = new DateTime?(DateTime.Parse(row["PositionEndDate2"].ToString()));
                    }
                    item.PositionNo2 = row["PositionNo2"].ToString();
                    if (row["PositionDate2"].ToString() != "")
                    {
                        item.PositionDate2 = new DateTime?(DateTime.Parse(row["PositionDate2"].ToString()));
                    }
                    item.PositionRemark2 = row["PositionRemark2"].ToString();
                    item.Class = row["Class"].ToString();
                    if (row["ClassDate"].ToString() != "")
                    {
                        item.ClassDate = new DateTime?(DateTime.Parse(row["ClassDate"].ToString()));
                    }
                    if (row["IsLeave"].ToString() != "")
                    {
                        item.IsLeave = new int?(int.Parse(row["IsLeave"].ToString()));
                    }
                    item.LeaveReasion = row["LeaveReasion"].ToString();
                    if (row["LeaveDay"].ToString() != "")
                    {
                        item.LeaveDay = new DateTime?(DateTime.Parse(row["LeaveDay"].ToString()));
                    }
                    if (row["UserID"].ToString() != "")
                    {
                        item.UserID = int.Parse(row["UserID"].ToString());
                    }
                    item.LeaveTo = row["LeaveTo"].ToString();
                    item.LeaveNo = row["LeaveNo"].ToString();
                    if (row["LeaveDate"].ToString() != "")
                    {
                        item.LeaveDate = new DateTime?(DateTime.Parse(row["LeaveDate"].ToString()));
                    }
                    item.LeaveSummary = row["LeaveSummary"].ToString();
                    item.LeaveRemark = row["LeaveRemark"].ToString();
                    item.AddUser = row["AddUser"].ToString();
                    if (row["AddDate"].ToString() != "")
                    {
                        item.AddDate = new DateTime?(DateTime.Parse(row["AddDate"].ToString()));
                    }
                    item.UpdateUser = row["UpdateUser"].ToString();
                    if (row["UpdateDate"].ToString() != "")
                    {
                        item.UpdateDate = new DateTime?(DateTime.Parse(row["UpdateDate"].ToString()));
                    }
                    item.Backup1 = row["Backup1"].ToString();
                    item.UserName = row["UserName"].ToString();
                    item.Backup2 = row["Backup2"].ToString();
                    item.Backup3 = row["Backup3"].ToString();
                    item.Backup4 = row["Backup4"].ToString();
                    item.Backup5 = row["Backup5"].ToString();
                    item.Backup6 = row["Backup6"].ToString();
                    item.Backup7 = row["Backup7"].ToString();
                    item.Sex = row["Sex"].ToString();
                    list.Add(item);
                }
            }
            return list;
        }

        public UserChangeLog GetModel(int LogID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select *");
            builder.Append("  from view_UserChangeLog ");
            builder.Append(" where LogID=@LogID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@LogID", SqlDbType.Int, 4) };
            cmdParms[0].Value = LogID;
            UserChangeLog log = new UserChangeLog();
            DataSet set = DBHelper.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                DataRow row = set.Tables[0].Rows[0];
                if (row["LogID"].ToString() != "")
                {
                    log.LogID = int.Parse(row["LogID"].ToString());
                }
                log.IUserName = row["IUserName"].ToString();
                if (row["Birthday"].ToString() != "")
                {
                    log.Birthday = new DateTime?(DateTime.Parse(row["Birthday"].ToString()));
                }
                log.ID = row["ID"].ToString();
                log.Birthplace = row["Birthplace"].ToString();
                log.Nation = row["Nation"].ToString();
                log.Politics = row["Politics"].ToString();
                if (row["JoinPartDate"].ToString() != "")
                {
                    log.JoinPartDate = new DateTime?(DateTime.Parse(row["JoinPartDate"].ToString()));
                }
                if (row["GraduationDate"].ToString() != "")
                {
                    log.GraduationDate = new DateTime?(DateTime.Parse(row["GraduationDate"].ToString()));
                }
                log.GraduationSchoole = row["GraduationSchoole"].ToString();
                log.HighestEducation = row["HighestEducation"].ToString();
                log.Degree = row["Degree"].ToString();
                log.LogType = row["LogType"].ToString();
                log.Major = row["Major"].ToString();
                if (row["JoinWorkDate"].ToString() != "")
                {
                    log.JoinWorkDate = new DateTime?(DateTime.Parse(row["JoinWorkDate"].ToString()));
                }
                log.Photo = row["Photo"].ToString();
                if (row["IsOfficer"].ToString() != "")
                {
                    log.IsOfficer = new int?(int.Parse(row["IsOfficer"].ToString()));
                }
                log.Remark = row["Remark"].ToString();
                if (row["RegistDay"].ToString() != "")
                {
                    log.RegistDay = new DateTime?(DateTime.Parse(row["RegistDay"].ToString()));
                }
                log.RegistWay = row["RegistWay"].ToString();
                log.RegistFrom = row["RegistFrom"].ToString();
                log.RegistTo = row["RegistTo"].ToString();
                if (row["OrganID"].ToString() != "")
                {
                    log.OrganID = new int?(int.Parse(row["OrganID"].ToString()));
                }
                log.RegistNo = row["RegistNo"].ToString();
                log.CheckState = row["CheckState"].ToString();
                if (row["RegistDate"].ToString() != "")
                {
                    log.RegistDate = new DateTime?(DateTime.Parse(row["RegistDate"].ToString()));
                }
                log.RegistSummary = row["RegistSummary"].ToString();
                log.RegistRemark = row["RegistRemark"].ToString();
                log.RegistState = row["RegistState"].ToString();
                log.RegistType = row["RegistType"].ToString();
                log.UserType = row["UserType"].ToString();
                if (row["IsHeighWith"].ToString() != "")
                {
                    log.IsHeighWith = new int?(int.Parse(row["IsHeighWith"].ToString()));
                }
                log.JobPositionType = row["JobPositionType"].ToString();
                log.JobPositionName1 = row["JobPositionName1"].ToString();
                if (row["JobPositionDate1"].ToString() != "")
                {
                    log.JobPositionDate1 = new DateTime?(DateTime.Parse(row["JobPositionDate1"].ToString()));
                }
                if (row["CheckAdminID"].ToString() != "")
                {
                    log.CheckAdminID = int.Parse(row["CheckAdminID"].ToString());
                }
                log.JobPositionName2 = row["JobPositionName2"].ToString();
                if (row["JobPositionDate2"].ToString() != "")
                {
                    log.JobPositionDate2 = new DateTime?(DateTime.Parse(row["JobPositionDate2"].ToString()));
                }
                log.JobPositionNo = row["JobPositionNo"].ToString();
                if (row["JobPositionDate"].ToString() != "")
                {
                    log.JobPositionDate = new DateTime?(DateTime.Parse(row["JobPositionDate"].ToString()));
                }
                log.JobPositionSummary = row["JobPositionSummary"].ToString();
                log.JobPositionRemark = row["JobPositionRemark"].ToString();
                log.AdminPosition = row["AdminPosition"].ToString();
                if (row["EvaluationDate"].ToString() != "")
                {
                    log.EvaluationDate = new DateTime?(DateTime.Parse(row["EvaluationDate"].ToString()));
                }
                log.Position1 = row["Position1"].ToString();
                log.PositionLevel1 = row["PositionLevel1"].ToString();
                if (row["CheckDate"].ToString() != "")
                {
                    log.CheckDate = new DateTime?(DateTime.Parse(row["CheckDate"].ToString()));
                }
                log.JobTitle1 = row["JobTitle1"].ToString();
                if (row["PositionStartDate1"].ToString() != "")
                {
                    log.PositionStartDate1 = new DateTime?(DateTime.Parse(row["PositionStartDate1"].ToString()));
                }
                if (row["PositionEndDate1"].ToString() != "")
                {
                    log.PositionEndDate1 = new DateTime?(DateTime.Parse(row["PositionEndDate1"].ToString()));
                }
                log.PositionNo1 = row["PositionNo1"].ToString();
                if (row["PositionDate1"].ToString() != "")
                {
                    log.PositionDate1 = new DateTime?(DateTime.Parse(row["PositionDate1"].ToString()));
                }
                log.PositionRemark1 = row["PositionRemark1"].ToString();
                if (row["IsDoublePosition"].ToString() != "")
                {
                    log.IsDoublePosition = new int?(int.Parse(row["IsDoublePosition"].ToString()));
                }
                log.Position2 = row["Position2"].ToString();
                log.PositionLevel2 = row["PositionLevel2"].ToString();
                log.JobTitle2 = row["JobTitle2"].ToString();
                log.CheckRemark = row["CheckRemark"].ToString();
                if (row["PositionStartDate2"].ToString() != "")
                {
                    log.PositionStartDate2 = new DateTime?(DateTime.Parse(row["PositionStartDate2"].ToString()));
                }
                if (row["PositionEndDate2"].ToString() != "")
                {
                    log.PositionEndDate2 = new DateTime?(DateTime.Parse(row["PositionEndDate2"].ToString()));
                }
                log.PositionNo2 = row["PositionNo2"].ToString();
                if (row["PositionDate2"].ToString() != "")
                {
                    log.PositionDate2 = new DateTime?(DateTime.Parse(row["PositionDate2"].ToString()));
                }
                log.PositionRemark2 = row["PositionRemark2"].ToString();
                log.Class = row["Class"].ToString();
                if (row["ClassDate"].ToString() != "")
                {
                    log.ClassDate = new DateTime?(DateTime.Parse(row["ClassDate"].ToString()));
                }
                if (row["IsLeave"].ToString() != "")
                {
                    log.IsLeave = new int?(int.Parse(row["IsLeave"].ToString()));
                }
                log.LeaveReasion = row["LeaveReasion"].ToString();
                if (row["LeaveDay"].ToString() != "")
                {
                    log.LeaveDay = new DateTime?(DateTime.Parse(row["LeaveDay"].ToString()));
                }
                if (row["UserID"].ToString() != "")
                {
                    log.UserID = int.Parse(row["UserID"].ToString());
                }
                log.LeaveTo = row["LeaveTo"].ToString();
                log.LeaveNo = row["LeaveNo"].ToString();
                if (row["LeaveDate"].ToString() != "")
                {
                    log.LeaveDate = new DateTime?(DateTime.Parse(row["LeaveDate"].ToString()));
                }
                log.LeaveSummary = row["LeaveSummary"].ToString();
                log.LeaveRemark = row["LeaveRemark"].ToString();
                log.AddUser = row["AddUser"].ToString();
                if (row["AddDate"].ToString() != "")
                {
                    log.AddDate = new DateTime?(DateTime.Parse(row["AddDate"].ToString()));
                }
                log.UpdateUser = row["UpdateUser"].ToString();
                if (row["UpdateDate"].ToString() != "")
                {
                    log.UpdateDate = new DateTime?(DateTime.Parse(row["UpdateDate"].ToString()));
                }
                log.Backup1 = row["Backup1"].ToString();
                log.UserName = row["UserName"].ToString();
                log.Backup2 = row["Backup2"].ToString();
                log.Backup3 = row["Backup3"].ToString();
                log.Backup4 = row["Backup4"].ToString();
                log.Backup5 = row["Backup5"].ToString();
                log.Backup6 = row["Backup6"].ToString();
                log.Backup7 = row["Backup7"].ToString();
                log.Sex = row["Sex"].ToString();
                return log;
            }
            return null;
        }

        public bool UpdateUserID(int logID, int userid)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update UserChangeLog set ");
            builder.Append(" UserID = @UserID ");
            builder.Append(" where LogID=@LogID ");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@LogID", logID), new SqlParameter("@UserID", userid) };
            return (DBHelper.ExecuteSql(builder.ToString(), cmdParms) > 0);
        }
    }
}

